import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_global.dart';
import 'package:flutter_learn_vi/src/bean/bean_mine_uestion.dart';
import 'package:flutter_learn_vi/src/common/global.dart';
import 'package:flutter_learn_vi/src/page/home/new/study_item_widget.dart';
import 'package:flutter_learn_vi/src/page/mine/question_model.dart';

import '../../catalogue/catalogue_article_page.dart';
import '../../catalogue/catalogue_news_page.dart';
import '../../mine/new/wangpo/integral_stat_tab_page.dart';
import '../../study/main_exam_page.dart';
import '../../study/main_video_v2_page.dart';
import '../../train/tain_main_page.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/5.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class HomeitemStudyV2Widget extends StatefulWidget {
  @override
  _HomeitemStudyWidgetState createState() => _HomeitemStudyWidgetState();
}

class _HomeitemStudyWidgetState extends State<HomeitemStudyV2Widget>
    with MineQuestionModel {
  @override
  void initState() {
    super.initState();
    initData();
  }

  StudyModelBean _studyModelBean;

  void initData() async {
    _studyModelBean = await getStudyModel();
    if (_studyModelBean != null) {
      rootStreamController.add(GlobalBean(204, true));
    }
  }

  @override
  Widget build(BuildContext context) {
    if (_studyModelBean == null) {
      return Container();
    }
    // 每日练习-我的培训-新闻资讯-排行榜
    //2025年01月24日修改的需求
    if (0 == 0) {
      StudyModelItemBean itemBean1 = StudyModelItemBean("每日练习", null, -2);
      itemBean1.nodeLogo = "assets/images/3.0x/learning-record.png";
      itemBean1.page = MainExamPage();
      itemBean1.nodeType = "APP-Native";

      StudyModelItemBean itemBean2 = StudyModelItemBean("我的培训", null, -2);
      itemBean2.nodeLogo = "assets/images/3.0x/home_peixun.png";
      itemBean2.page = TrainMainPage();
      itemBean2.nodeType = "APP-Native";

      StudyModelItemBean itemBean3 = StudyModelItemBean("新闻资讯", null, -2);
      itemBean3.nodeName = "新闻资讯";
      itemBean3.nodeLogo = "assets/images/3.0x/home_news.png";
      itemBean3.page = CatalogueNewsNotiaMainPage();
      itemBean3.nodeType = "APP-Native";

      StudyModelItemBean itemBean4 = StudyModelItemBean("排行榜", null, -2);
      itemBean4.nodeType = "APP-Native";
      itemBean4.nodeLogo = "assets/images/3.0x/home_paihang.png";
      itemBean4.page = IntegralAllMineStatTabPage();

      return Container(
        margin: EdgeInsets.only(top: 2, bottom: 1),
        padding: EdgeInsets.only(bottom: 12, top: 8),
        color: Colors.white,
        child: Row(
          children: [
            Expanded(
              child: StudyItemWidget(
                itemBean1,
                pading: 10,
                maxLines: 1,
                width: 28,
              ),
            ),
            Expanded(
              child: StudyItemWidget(
                itemBean2,
                pading: 10,
                maxLines: 1,
                width: 28,
              ),
            ),
            Expanded(
              child: StudyItemWidget(
                itemBean3,
                pading: 10,
                maxLines: 1,
                width: 28,
              ),
            ),
            Expanded(
              child: StudyItemWidget(
                itemBean4,
                pading: 10,
                maxLines: 1,
                width: 28,
              ),
            ),
          ],
        ),
      );
    }
    return Container(
      margin: EdgeInsets.only(top: 16, bottom: 10),
      color: Colors.white,
      height: 85,
      child: ListView.builder(
          padding: EdgeInsets.zero,
          scrollDirection: Axis.horizontal,
          shrinkWrap: true,
          //itemCount: _studyModelBean.studyModelItemList.length,
          itemCount: 6,
          itemBuilder: (BuildContext context, int index) {
            StudyModelItemBean itemBean;
            if (index == 0) {
              itemBean = StudyModelItemBean("每日练习", null, -2);
              itemBean.nodeLogo = "assets/images/2.0x/home_study.png";
              itemBean.page = MainExamPage();
              itemBean.nodeType = "APP-Native";
            } else if (index == 1) {
              itemBean = StudyModelItemBean("新闻资讯", null, -2);
              itemBean.nodeName = "新闻资讯";
              itemBean.nodeLogo = "assets/images/2.0x/home_news.png";
              itemBean.page = CatalogueNewsNotiaMainPage();
              itemBean.nodeType = "APP-Native";
            } else if (index == 2) {
              itemBean = StudyModelItemBean("文章阅读", null, -2);
              itemBean.nodeType = "APP-Native";
              itemBean.nodeLogo = "assets/images/2.0x/article_icon.png";
              itemBean.nodeName = "文章阅读";
              itemBean.page = CatalogueArticleMainPage();
            } else if (index == 3) {
              itemBean = StudyModelItemBean("视频学习", null, -2);
              itemBean.nodeType = "APP-Native";
              itemBean.nodeLogo = "assets/images/2.0x/home_video.png";
              itemBean.page = VideoStudyMainV2Page();
            } else if (index == 4) {
              itemBean = StudyModelItemBean("排行榜", null, -2);
              itemBean.nodeType = "APP-Native";
              itemBean.nodeLogo = "assets/images/2.0x/home_paihang.png";
              itemBean.page = IntegralAllMineStatTabPage();
            } else if (index == 5) {
              itemBean = StudyModelItemBean("我的培训", null, -2);
              itemBean.nodeLogo = "assets/images/2.0x/home_study.png";
              itemBean.page = TrainMainPage();
              itemBean.nodeType = "APP-Native";
            }
            return Container(
              height: 55,
              width: 66,
              child: StudyItemWidget(
                itemBean,
                pading: 10,
                maxLines: 1,
                width: 28,
              ),
            );
          }),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
